#ifndef MqttServiceClass
#define MqttServiceClass
#include <sys/time.h>
#include <unistd.h>
#include <thread>
#include "lib/json/json/json.h"
#include "MqttConnection.h"
#include "lib/ThreadPool.hpp"
#include "lib/sole/sole.hpp"
class MqttService
{
private:
    std::unordered_map<std::string, MqttConnection *> nameConnectionMap;
    std::unordered_map<std::string, MqttConnection *> uuidConnectionMap;
    ThreadPool *threadPool;
    static void nonStopLoop(MqttService *p);
    MqttService();
    
public:
    static MqttService& getInstance();
    MqttConnection *addConnection(const std::string &name,
                                  const std::string &address,
                                  bool enable = false,
                                  int port = 1883,
                                  const std::string &uuid = "",
                                  const std::string &userName = "",
                                  const std::string &password = "");
    static std::string genUUID();
    MqttConnection *getConnectionByName(const std::string &name);
    MqttConnection *getConnectionByUUID(const std::string &uuid);
    void removeConnectionByName(const std::string &name);
    void removeConnectionByUUID(const std::string &uuid);
    Json::Value getConnectionJson(const std::string &uuid);
    Json::Value getConnectionList();
    ~MqttService();
};
#endif